package sketch.generator.examples;

import sketch.generator.ChainValueGenerator;
import sketch.generator.NondetValueGenerator;
import sketch.generator.RandomValueGenerator;
import sketch.generator.SingleValueGenerator;
import sketch.util.Globals;
import sketch.util.SketchUtil;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;


public class PairGeneratorTest extends TestCase {
	

	public static Test suite() {
        return new TestSuite(PairGeneratorTest.class);
    }
	
	public void testPairGeneratorTwoChains() {
		SketchUtil.stdln("Executing testPairGeneratorTwoChains");
		ChainValueGenerator<String> chainString = new ChainValueGenerator<String>();
		chainString.add(new String[]{"string 1", "string 2", "string 3"});
		ChainValueGenerator<Integer> chainInt = new ChainValueGenerator<Integer>();
		chainInt.add(new Integer[]{4, 5, 6});
		
		PairGenerator<String, Integer> pairGen = new PairGenerator<String, Integer>(chainString, chainInt);
		//SketchUtil.stdln(pairGen.hasNext());
		int count = 0;
		while(pairGen.hasNext()) {
			SketchUtil.stdln(pairGen.next());
			count++;
		}
		SketchUtil.stdln(Globals.lineSep);
		assertTrue(count == 9);
	}
	
	public void testPairGeneratorChainRandom() {
		SketchUtil.stdln("Executing testPairGeneratorChainRandom");
		RandomValueGenerator<String> randomString = new RandomValueGenerator<String>();
		randomString.add(new String[]{"random 1", "random 2", "random 3"});
		RandomValueGenerator<Integer> randomInt = new RandomValueGenerator<Integer>();
		randomInt.add(new Integer[]{4, 5, 6});
		
		PairGenerator<String, Integer> pairGen = new PairGenerator<String, Integer>(randomString, randomInt);
		//SketchUtil.stdln(pairGen.hasNext());
		int i = 10;
		int count = 0;
		int expected = i;
		while (i-- > 0) {
		    while(pairGen.hasNext()) {
			    SketchUtil.stdln(pairGen.next());
			    count++;
		    }
		    pairGen.reset();
		}
		SketchUtil.stdln(Globals.lineSep);
		assertTrue(count == expected);
	}
	
	public void testPairGeneratorSingleValueGen() {
		SketchUtil.stdln("Executing testPairGeneratorSingleValueGen");
		SingleValueGenerator<String> singleString1 = new SingleValueGenerator<String>("single1");
		SingleValueGenerator<String> singleString2 = new SingleValueGenerator<String>("single2");
		PairGenerator<String, String> pairGen = new PairGenerator<String, String>(singleString1, singleString2);
		int count = 0;
		while(pairGen.hasNext()) {
			SketchUtil.stdln(pairGen.next());
			count++;
		}
		SketchUtil.stdln(Globals.lineSep);
		assertTrue(count == 1);
	}
	
	public void testPairGeneratorChainSingleValueGen() {
		SketchUtil.stdln("Executing testPairGeneratorSingleValueGen");
		ChainValueGenerator<String> chainString = new ChainValueGenerator<String>();
		chainString.add(new String[]{"string 1", "string 2", "string 3"});
		SingleValueGenerator<String> singleString2 = new SingleValueGenerator<String>("single2");
		PairGenerator<String, String> pairGen = new PairGenerator<String, String>(chainString, singleString2);
		int count = 0;
		while(pairGen.hasNext()) {
			SketchUtil.stdln(pairGen.next());
			count++;
		}
		SketchUtil.stdln(Globals.lineSep);
		assertTrue(count == 3);
	}
	
	public void testPairGeneratorChainNondeter() {
		SketchUtil.stdln("Executing testPairGeneratorChainNondeter");
		ChainValueGenerator<String> chainString = new ChainValueGenerator<String>();
		chainString.add(new String[]{"string 1", "string 2", "string 3"});
		NondetValueGenerator<String> nondetString = new NondetValueGenerator<String>("non-deter1", "non-deter2", "non-deter3");
		PairGenerator<String, String> pairGen = new PairGenerator<String, String>(chainString, nondetString);
		int count = 0;
		while(pairGen.hasNext()) {
			SketchUtil.stdln(pairGen.next());
			count++;
		}
		SketchUtil.stdln(Globals.lineSep);
		assertTrue(count == 9);
	}
}
